package com.csjung.games.gamenori.server.domain;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.PrePersist;

@Entity
public class User implements Serializable{

  /**
   * 
   */
  private static final long serialVersionUID = 1L;

  public static User findUser(Long id) {
    if (id == null) {
      return null;
    }

    EMF emf = EMF.get();
    User user = emf.ofy().find(User.class, id);
    return user;
  }

  @Id
  Long id;
  
  private String userId;

  private String nickname;
  
  private String channelToken;

  private Integer version = 0;

  /**
   * Get the version of this datastore object.
   */
  public Integer getVersion() {
    return version;
  }

  /**
   * Get the unique ID of the Task.
   */
  public Long getId() {
    return id;
  }

  /**
   * Get the name of the Task.
   */
  public String getNickname() {
    return nickname;
  }

  /**
   * Persist this object in the data store.
   */
  public void persist() {
    EMF emf = EMF.get();

    ++version;
    emf.ofy().put(this);
    
  }

  public void setId(Long id) {
    this.id = id;
  }

  /**
   * Set the name of the task.
   * 
   * @param name the task name
   */
  public void setNickname(String nickname) {
    this.nickname = nickname;
  }

  @PrePersist
  void onPersist() {
    ++this.version;
  }

  public String getChannelToken() {
    return channelToken;
  }

  public void setChannelToken(String channelToken) {
    this.channelToken = channelToken;
  }

  public String getUserId() {
    return userId;
  }

  public void setUserId(String userId) {
    this.userId = userId;
  }

}
